<?php
/*
	插件概览
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$plugin_name = $_RQ['basicname'] ? $_RQ['basicname'] : '';
if($_RQ['op']=='list'){
	//显示统计数据
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$mounthtime =  mktime(0,0,0,date('m'),1,date('Y'));
	$yeartime=strtotime(date('Y-m-d',mktime(0, 0 , 0,1,1,date("Y"))));
	$data['monthfee']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$mounthtime),'price');
	$data['monthorder']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$mounthtime));
	$data['yearfee']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$yeartime),'price');
	$data['yearnums']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$yeartime));
	//$data['yearmembers']=pdo_getnorepeat('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$yeartime),'mid');
	//$data['yearmembers']=count($data['yearmembers']);
	$data['yearmembers']=pdo_count('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$yeartime));
	//7日销量走势图
	$month12=array();
	for($i=0;$i<7;$i++){
			if($i==0){
				$dayend = $daytime;
				$daystart = $dayend-24*3600;
			}else{
				$dayend = $daytime-$i*24*3600;
				$daystart = $dayend-24*3600;
			}
			$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>array(1,2,3,5,6));
			$params['createtime between']=array($daystart,$dayend);
			$month12[] = date('m-d',$daystart);
			$monthorder[]=pdo_count('jy_weishop_order',$params);
			$monthfee=pdo_getsum('jy_weishop_order',$params,'price');
			$monthmoney[]=intval($monthfee);
	}
	$monthorder=array_reverse($monthorder);
	$monthmoney=array_reverse($monthmoney);
	$month12=array_reverse($month12);
	$return['data01']=array(
		'datas'=>array(
			array('name'=>'成交订单数','value'=>$monthorder),
			array('name'=>'成交订单金额','value'=>$monthmoney),
		),
		'xdatas'=>$month12,
	);
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$brands=pdo_getall('jy_weishop_goods_brand',$params,array('id','title'));
	foreach($brands as $k=>&$v){
		$goodsid=pdo_getall('jy_weishop_goods',array('brandid'=>$v['id'],'uniacid'=>$_SESSION['uniacid']),array('id'),'id');
		if($goodsid){
			$goodsid=array_keys($goodsid);
		}else{
			$goodsid=-1;
		}
		$v['total']=pdo_getsum('jy_weishop_order_goods',array('ispay'=>1,'goodsid'=>$goodsid,'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$mounthtime),'total');
	}
	paixu($brands,'total','desc');
	$values=$names=array();
	$i=1;
	foreach($brands as $v){
		$i ++;
		$names[]=$v['title'];
		$values[]=$v['total'];
		if($i>=5){
			break;
		}
	}
	$return['data03']=array(
		'names'=>$names,
		'values'=>$values,
	);
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$levels=pdo_getall('jy_weishop_member_level',$params,array('id','title'));
	$levels[]=array('id'=>0,'title'=>'默认等级');
	foreach($levels as $k=>&$v){
		$mids=pdo_getall('jy_weishop_member',array('level'=>$v['id'],'uniacid'=>$_SESSION['uniacid']),'mid','mid');
		if($mids){
			$mids=array_keys($mids);
		}else{
			$mids=-1;
		}
		$v['total']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mids,'ispay'=>1,'createtime >'=>$mounthtime));
		$mids=pdo_getall('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$mounthtime),'mid','mid');
		if($mids){
			$mids=array_keys($mids);
		}else{
			$mids=-1;
		}
		$v['total2']=pdo_count('jy_weishop_member',array('level'=>$v['id'],'mid'=>$mids,'uniacid'=>$_SESSION['uniacid']));
	}
	paixu($levels,'total','desc');
	$values=$names=array();
	$orderuser=$members=0;
	foreach($levels as $nv){
		$names[]=$nv['title'];
		$values[]=$nv['total'];
		$values2[]=$nv['total2'];
		$orderuser +=$nv['total2'];
		if($nv['id']){
			$members +=$nv['total2'];
		}
	}
	$return['data04']=array(
		'names'=>$names,
		'values1'=>$values,
		'values2'=>$values2,
	);
	$allmembers=pdo_count('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$mounthtime));
	$ordernum=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$mounthtime));
	$return['data02']=array(
		'names'=>array('访客','成交客户数','订单数','等级客户数'),
		'values'=>array($allmembers,$orderuser,$ordernum,$members),
	);
	$return['data']=$data;
	$return['shopset']=$this->plugin_setting('shopset');
	$return['logo']=$return['shopset']['logo']?:'../addons/jy_weishop/resource/images/logo.png';
	exi($return);
}
if($_RQ['op']=='mlist'){
	//显示统计数据
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$mounthtime =  mktime(0,0,0,date('m'),1,date('Y'));
	$yeartime=strtotime(date('Y-m-d',mktime(0, 0 , 0,1,1,date("Y"))));
	$data['monthfee']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$mounthtime),'price');
	$data['monthorder']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$mounthtime));
	$data['yearfee']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$yeartime),'price');
	$data['yearnums']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$yeartime));
	//$data['yearmembers']=pdo_getnorepeat('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$yeartime),'mid');
	//$data['yearmembers']=count($data['yearmembers']);
	$data['yearmembers']=pdo_count('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$yeartime));
	//7日销量走势图
	$month12=array();
	for($i=0;$i<7;$i++){
			if($i==0){
				$dayend = $daytime;
				$daystart = $dayend-24*3600;
			}else{
				$dayend = $daytime-$i*24*3600;
				$daystart = $dayend-24*3600;
			}
			$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>array(1,2,3,5,6));
			$params['createtime between']=array($daystart,$dayend);
			$month12[] = date('m-d',$daystart);
			$monthorder[]=pdo_count('jy_weishop_order',$params);
			$monthfee=pdo_getsum('jy_weishop_order',$params,'price');
			$monthmoney[]=intval($monthfee);
	}
	$monthorder=array_reverse($monthorder);
	$monthmoney=array_reverse($monthmoney);
	$month12=array_reverse($month12);
	$return['data01']=array(
		'datas'=>array(
			array('name'=>'成交订单数','value'=>$monthorder),
			array('name'=>'成交订单金额','value'=>$monthmoney),
		),
		'xdatas'=>$month12,
	);
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$brands=pdo_getall('jy_weishop_goods_brand',$params,array('id','title'));
	foreach($brands as $k=>&$v){
		$goodsid=pdo_getall('jy_weishop_goods',array('brandid'=>$v['id'],'uniacid'=>$_SESSION['uniacid']),array('id'),'id');
		if($goodsid){
			$goodsid=array_keys($goodsid);
		}else{
			$goodsid=-1;
		}
		$v['total']=pdo_getsum('jy_weishop_order_goods',array('ispay'=>1,'goodsid'=>$goodsid,'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$mounthtime),'total');
	}
	paixu($brands,'total','desc');
	$values=$names=array();
	$i=1;
	foreach($brands as $v){
		$i ++;
		$names[]=$v['title'];
		$values[]=$v['total'];
		if($i>=5){
			break;
		}
	}
	$return['data03']=array(
		'names'=>$names,
		'values'=>$values,
	);
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$levels=pdo_getall('jy_weishop_member_level',$params,array('id','title'));
	$levels[]=array('id'=>0,'title'=>'默认等级');
	foreach($levels as $k=>&$v){
		$mids=pdo_getall('jy_weishop_member',array('level'=>$v['id'],'uniacid'=>$_SESSION['uniacid']),'mid','mid');
		if($mids){
			$mids=array_keys($mids);
		}else{
			$mids=-1;
		}
		$v['total']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mids,'ispay'=>1,'createtime >'=>$mounthtime));
		$mids=pdo_getall('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$mounthtime),'mid','mid');
		if($mids){
			$mids=array_keys($mids);
		}else{
			$mids=-1;
		}
		$v['total2']=pdo_count('jy_weishop_member',array('level'=>$v['id'],'mid'=>$mids,'uniacid'=>$_SESSION['uniacid']));
	}
	paixu($levels,'total','desc');
	$values=$names=array();
	$orderuser=$members=0;
	foreach($levels as $nv){
		$names[]=$nv['title'];
		$values[]=$nv['total'];
		$values2[]=$nv['total2'];
		$orderuser +=$nv['total2'];
		if($nv['id']){
			$members +=$nv['total2'];
		}
	}
	$return['data04']=array(
		'names'=>$names,
		'values1'=>$values,
		'values2'=>$values2,
	);
	$allmembers=pdo_count('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$mounthtime));
	$ordernum=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$mounthtime));
	$return['data02']=array(
		'names'=>array('访客','成交客户数','订单数','等级客户数'),
		'values'=>array($allmembers,$orderuser,$ordernum,$members),
	);
	$return['data']=$data;
	$return['shopset']=$this->plugin_setting('shopset');
	$return['logo']=$return['shopset']['logo']?:'../addons/jy_weishop/resource/images/logo.png';
	exi($return);
}